package com.example.multiredis.service;

import com.example.multiredis.util.SpringBeanUtil;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/8/30 22:13
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */

public class Test {

/*    @Autowired
    @Qualifier("redisTemplate")
    private RedisTemplate redisTemplate;

    @Autowired
    @Qualifier("secondRedisTemplate")
    private RedisTemplate secondRedisTemplate;*/

    public String test() {

        // 方式一
/*        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(Appconfig.class);
        Object testService = ac.getBean("testService");
        return null;
*/
        // 方式二
//        RedisTemplate redisTemplate = SpringBeanUtil.getBean(RedisTemplate.class);    // 选择第一个数据源
        RedisTemplate redisTemplate = SpringBeanUtil.getBean("secondRedisTemplate",RedisTemplate.class);// 选择第二个数据源
        RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
        DefaultStringRedisConnection stringRedisConnection = new DefaultStringRedisConnection(redisConnection);




        redisTemplate.opsForValue().set("zjq","zjq");
        return (String) redisTemplate.opsForValue().get("zjq");


    }
}
